<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="WEB-INF/pager-taglib.tld" prefix="pg" %>

<%
String path = request.getContextPath();
String newPath="";
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
    
  <html xmlns="http://www.w3.org/1999/xhtml">
<head>
		<base href="<%=basePath%>" />
		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="css/magic-bootstrap.css" rel="stylesheet"></link>
		<link href="css/styles.css" rel="stylesheet"></link>
		<link href="css/div.css" rel="stylesheet" type="text/css"></link>
		<link href="css/u4.css" rel="stylesheet" type="text/css"></link>
		
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/lavalamp.js"></script>
		<script type="text/javascript" src="js/jquery.js"></script>
		<script type="text/javascript" src="js/bootstrap-dropdown.js"></script>
		<script type="text/javascript" src="js/bootstrap-collapse.js"></script>
		<script type="text/javascript" src="js/bootstrap-tab.js"></script>
	
		<script type="text/javascript" src="js/bootstrap-carousel.js"></script>
		
		<script type="text/javascript" src="js/verify.js"></script>
		
		<script type="text/javascript" >
		
		$(document).ready(function(){
			$("#1").addClass("active");
			$("#li1").addClass("active");
			var firstobjs;
			init();
			
			$("#firstClassList").change(function(){showSeconds();});
			$("#type").change(function(){
				switch($(this).val()){
				case '1': $("#oldPriceDiv").show();break;
				case '2':$("#oldPriceDiv").hide();break;
				}
			});
		});
		
		function showSeconds(){
			$("#secondClassList").empty();
			$.each(firstobjs,function(index,item)
				{
					if(index+1==$("#firstClassList").val())
					{
						
						$.each(item["secondClasses"],function(index,it)
						{					
						$("<option></option>")
							.val(it["id"])
							.text(it["name"])
							.appendTo($("#secondClassList"));
						});
					}
				}
			);
			/*
			$.ajax({
				url:"classAction!showSecondListByFirstId?firstClassId="+$("#firstClassList").val(),
				type:"get",
				success:function(result,status)
				{
				
				var objs = eval("("+result+")");
					$.each(objs,function(index,item)
					{
					
						$("<option></option>")
							.val(item["id"])
							.text(item["name"])
							.appendTo($("#secondClassList"));
					});
					
				}
			});
			*/
			
		}
		
		function init(){
		/*一级菜单*/
			$.ajax(
			{
				url:"classAction!showFirst",
				type:"get",
				success:function(result,status)
				{
			//	alert("1result:"+result);
					
					firstobjs = eval("("+result+")");
					
					$.each(firstobjs,function(index,item)
					{
						$("<option></option>")
							.val(item["id"])
							.text(item["name"])
							.appendTo($("#firstClassList"));
					});
					
					
					var seconds = firstobjs[0]["secondClasses"];
					$.each(seconds,function(index,item)
					{
				
						$("<option></option>")
							.val(item["id"])
							.text(item["name"])
							.appendTo($("#secondClassList"));
					});
				}
				
			});
	
			/* 二级菜单*/
			/*
			$.ajax(
			{
				url:"classAction!showSecondListByFirstId?firstClassId=1",
				type:"get",
				success:function(result,status)
				{
					alert("2result:"+result);
					var objs = eval("("+result+")");
		//		alert("result:"+result+",objs:"+objs);
					$.each(objs,function(index,item)
					{
						$("<option></option>")
							.val(item["id"])
							.text(item["name"])
							.appendTo($("#secondClassList"));
					});
				}
				
			});
			*/
			
		}
		
		function showSecond(){
			$("#secondClassList").empty();
			$.ajax({
				url:"classAction!showSecondListByFirstId?firstClassId="+$("#firstClassList").val(),
				type:"get",
				success:function(result,status)
				{
					//alert("classAction!showSecondListByFirstId?firstClassId="+$("#firstClassList").val()+"\nshowsecond result:"+result);
					var objs = eval("("+result+")");
					$.each(objs,function(index,item)
					{
					
						$("<option></option>")
							.val(item["id"])
							.text(item["name"])
							.appendTo($("#secondClassList"));
					});
					
				}
			});
			
		}
		
		function buyChange(){
		alert("buy");
			$("#oldPriceDiv").hide();
		alert("buy");
		}
		
		function buyChange(){
			$("#oldPriceDiv").show();
		}
		
	
		</script>
	<style type="text/css">	
.fonts 
{     
      width:auto; margin-top:12px; 
      float:right; font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
      font-size:11px; 
      color:#999999;
      line-height:25px;
      letter-spacing:1px
}
	
	</style>
	</head>

<!-- Navigation -->

<%@ include file="header.jsp" %> <!--  导航条 -->

<!-- end of Navigation -->

<s:if test="#session.user==null  ">
	<% response.sendRedirect("login.jsp"); %>
</s:if>

<div class="main">

<div class="container-fluid">
    
<div class="row-fluid" class="fonts">	
<!-- 个人中心页面 -->

        <div class="row" style="margin-top:50px">
            <div class="span2">
			<fieldset>
			<legend><strong>个人中心</strong></legend>
                <div class="tabbable tabs-left">
                    <ul class="nav nav-tabs">
                        <li id="li1" ><a href="#1" data-toggle="tab"><i class="icon-user"></i>用户资料</a> </li>
                        <li id="li2" ><a href="#2" data-toggle="tab"><i class="icon-bookmark"></i>资料修改</a> </li>
                        <li id="li3" ><a href="#3" data-toggle="tab"><i class="icon-tag"></i>发布信息</a> </li>
                    </ul>
                </div>
				</fieldset>
            </div>
            <div class="span9">
                <div class="tab-content">
                
    <div class="tab-pane" id="1">
                    <div class="form-horizontal">
                        <h4><strong>我的资料</strong></h4><br><br>
                        <div class="control-group">
                            <label class="control-label" for="userName">用户名:</label>
                            <div class="controls">
                               <s:property value="#session.user.name"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="userEmail">邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</label>
                            <div class="controls">
                               <s:property value="#session.user.name"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="userPhone">手&nbsp;&nbsp;&nbsp;&nbsp;机:</label>
                            <div class="controls">
                               <s:property value="#session.user.phone"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="userQQ">Q&nbsp;&nbsp;&nbsp;&nbsp;Q&nbsp;&nbsp;:</label>
                            <div class="controls">
                                <s:property value="#session.user.qq"/>
                            </div>
                        </div>
       <!-- 发布商品 -->
                      <div class="control-group">
                            <label class="">我发布的商品:</label>
    
                  
	<s:if test="#request.isIndex==null">

		<s:action name="goodsAction!showGoodsByUserIdIndex" namespace="/" executeResult="false">
			<s:param name="userId"><s:property value='#session.user.email'/></s:param>
		</s:action>		 
	</s:if>                       
        <table class="table table-striped table-bordered table-condensed">
	        <thead>
          <tr>
          	<th>类型</th>
            <th>商品名</th>
            <th>价格</th>
            <th>发布时间</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
        <s:iterator value="#request.goodsList" id="goods">
          <tr>
           <td><s:if test="#goods.type==2">
           			求购
           	   </s:if>
           	   <s:else>
           	   		卖出
           	   </s:else>
           	</td>
         
            <td><s:property value="#goods.name"/></td>
             <td><s:property value="#goods.price"/>元</td>
            <td><s:date name="#goods.publishTime" format="yyyy-MM-dd HH:mm"/></td>
            <td><a class="btn btn-danger" href="goodsAction!deleteGoodsById?id=<s:property value='#goods.id'/>">删除</a>
<!--             <a class="btn btn-danger" style="margin-left:20px">编辑</a> -->
            </td>
          </tr>
        </s:iterator>
        </tbody>
      </table>
      
      <!--  Page  -->
			<div class="row">
				   <div class="span9" style="margin-left:50px">
					<div class="page">
						<p id="page">
				<pg:pager scope="request" maxIndexPages="5" index="center"
						maxPageItems="5" url="goodsAction!showGoodsByUserIdInPage" items="${totalSize}" export="currentPageNumber=pageNumber">
       
       					 <pg:first>
							<a href="${pageUrl}" class="n">首页</a>
						</pg:first>
						<pg:prev>
							<a href="${pageUrl}" class="n">&lt;前一页</a>
						</pg:prev>
						
						<pg:page>
						</pg:page>
						
						<pg:pages>
							
							<c:choose>
								<c:when test="${pageNumber eq currentPageNumber }">
									<strong><span class="fk fk_cur"></span><span class="pc">${pageNumber }</span>
									</strong>
									
								</c:when>
								<c:otherwise>
									<a href="${pageUrl }"><span class="fk fkd"></span><span class="pc">${pageNumber}</span></a>
	  					    	</c:otherwise>
							</c:choose>
						</pg:pages>
						<pg:next>
							<a href="${pageUrl}" class="n">下一页&gt;</a>							
						</pg:next>
						<pg:last>
							<a href="${pageUrl}" class="n">尾页</a>
						</pg:last>
						
						<span class="nums"	style="margin-left:120px">共${totalSize}条记录</span>
					</pg:pager>
					</p>

					</div>
				 </div>
			  </div>
					<!--  end of page -->
					
                            
                        </div><!--  发布的商品 -->
                      
                    </div>
                </div>
  
	 <div class="tab-pane" id="2">
                    <form method="post" action="userAction!update" class="form-horizontal">
                        <h4><strong>修改个人信息</strong></h4><br><br>
                        <div class="control-group">
                            <label class="control-label" for="email">邮&nbsp;&nbsp;&nbsp;&nbsp;箱:</label>
                            <div class="controls">
                            <s:property value="#session.user.email"/>
<!--                                 <input type="text" name="email" value="" id="email" placeholder="请输入Email" class="control-input"> -->
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="name">用户名:</label>
                            <div class="controls">
                                <input type="text" name="name" value="<s:property value='#session.user.name'/>"  id="name" class="control-input"></input>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="phone">手&nbsp;&nbsp;&nbsp;&nbsp;机:</label>
                            <div class="controls">
                                <input type="text" name="phone" value="<s:property value='#session.user.phone'/>" id="phone" class="control-input"></input>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="qq">Q&nbsp;&nbsp;&nbsp;&nbsp;Q&nbsp;&nbsp;:</label>
                            <div class="controls">
                                <input type="text" name="qq" value="<s:property value='#session.user.qq'/>" id="qq" class="control-input"></input>
                            </div>
                        </div>
                        <hr>
                        <div class="control-group">
                            <label class="control-label">(可选)</label>
                            <div class="controls">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="password">原密码&nbsp;&nbsp;&nbsp;&nbsp;:</label>
                            <div class="controls">
                                <input type="password" value="" name="password" id="password" class="control-input"></input>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="newPassword">新密码&nbsp;&nbsp;&nbsp;&nbsp;:</label>
                            <div class="controls">
                                <input type="password" value="" name="newPassword" id="newPassword" class="control-input"></input>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="rePassword">确认密码:</label>
                            <div class="controls">
                                <input type="password" value="" name="rePassword" id="rePassword" class="control-input"></input>
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="controls">
                                <input type="submit" class="btn btn-large btn-primary" id="login" value="提交">
                            </div>
                        </div>
                    </form>
                </div>
                <!-- end of 管理信息  --> 
                   
<!-- 发布商品 -->
   <div class="tab-pane" id="3">
   
     <s:action name="classAction!showClass" namespace="/" executeResult="false"/>
                 
                    <form method="post" action="goodsAction!addNewGoods" class="form-horizontal" enctype="multipart/form-data">
                        <h4><strong>发布信息</strong></h4><br><br>
                        <div class="control-group">
                            <label class="control-label" for="productName">商品名称:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <input type="text" name="goods.name" onblur="Vproductname()" value="" id="productName" placeholder="请输入商品名称" class="control-input" style="height:30px"></input>
                           		<span id="infoProductName"></span>
                            </div>
                        </div>
                         <div class="control-group">
                            <label class="control-label" for="oriPrice">交易类型：</label>
                            <div class="controls">
                                <select id="type"  name="goods.type" class="control-input">
                                	<option value="1" >卖出</option>
                                	<option value="2" >求购</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="price">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <input type="text" onblur="Vprice()" name="goods.price" value="" id="price" class="control-input"></input>
                           		<span id="infoPrice"></span>
                            </div>
                        </div>
                        
                        <div class="control-group" id="oldPriceDiv">
                            <label class="control-label" for="oriPrice">原&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <input type="text" onblur="Voldprice()" name="goods.oldPrice" value="" id="oriPrice" class="control-input"></input>
                          		<span id="infoOldPrice"></span>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="oriPrice">总分类&nbsp;&nbsp;&nbsp;&nbsp;：</label>
                            <div class="controls">
                                <select id="firstClassList"  name="firstClass" class="control-input"></select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="oriPrice">子分类&nbsp;&nbsp;&nbsp;&nbsp;：</label>
                            <div class="controls">
                                <select id="secondClassList" name="secondId" class="control-input"></select>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="linkMan">联系人&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <input type="text" name="goods.contactName" value="" id="linkMan" class="control-input">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="location">交易地点:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <input type="text" name="goods.place" value="" id="location" class="control-input"></input>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="location">上传图片:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <input type="file" name="picFile" value="" id="location" class="control-input"></input>
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="description">商品描述:&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <div class="controls">
                                <textarea  name="goods.describe" value="" id="description"></textarea>
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="controls">
                                <input type="submit" class="btn btn-large btn-primary" value="提交"></input>
                            </div>
                        </div>
                    </form>
                </div>
<!-- end of 发布商品 -->



                </div>
            </div>
        </div>
<!-- 个人中心 -->

</div>

</div><!--container-->
</div>

</html>
  

